using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Models.Repositories;
	using TemplateWeb.Helpers;
	using System.Web.Security;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectNhaDat()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_NHADAT
			};
			return View(CreateViewModel(data));
		}

		public ActionResult SelectNhaDatPaging(int page = 1)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListNhaDat", CreateViewModel(data));
		}

		public ActionResult SelectNhaDatByLoaiBatDongSan(int idloaibatdongsan, int page = 1)
		{
			var data = new DataTransferViewModel
			{
				IDLoaiBatDongSan = idloaibatdongsan,
				EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
				CurrentPage = page
			};
			return View("SelectNhaDat", CreateViewModel(data));
		}

		public ActionResult SelectNhaDatByQuanHuyen(int idquanhuyen, int page = 1)
		{
			var data = new DataTransferViewModel
			{
				IDQuanHuyen = idquanhuyen,
				EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
				CurrentPage = page
			};
			return View("SelectNhaDat", CreateViewModel(data));
		}

        public ActionResult SelectNhaDatByLoaiBatDongSanQuanHuyen(int idloaibatdongsan, int idquanhuyen, int page = 1)
        {
            var data = new DataTransferViewModel
            {
                IDLoaiBatDongSan = idloaibatdongsan,
                IDQuanHuyen = idquanhuyen,
                EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
                CurrentPage = page
            };
            string tenloaibds = _repLoaiBatDongSan.SelectByID(idloaibatdongsan).TenLoaiBatDongSan.ToUpper();
            if (tenloaibds.Contains(WebConfiguration.NhaDatDuAn))
                return View("SelectNhaDatDuAn", CreateViewModel(data));
            else
            {
                if(tenloaibds.Contains(WebConfiguration.CanHo))
                    return View("SelectCanHoLe", CreateViewModel(data));
            }
            return View("SelectNhaDatLe", CreateViewModel(data));
        }

		public ActionResult SelectNhaDatByLoaiGia(int idloaigia, int page = 1)
		{
			var data = new DataTransferViewModel
			{
				IDLoaiGia = idloaigia,
				EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
				CurrentPage = page
			};
			return View("SelectNhaDat", CreateViewModel(data));
		}

		public ActionResult SelectNhaDatByNguoiDang(Guid idnguoidang, int page = 1)
		{
			var data = new DataTransferViewModel
			{
				IDNguoiDang = idnguoidang,
				EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
				CurrentPage = page
			};
			return View("SelectNhaDat", CreateViewModel(data));
		}


		[AcceptVerbs(HttpVerbs.Delete)]
		public JsonResult DeleteNhaDat(int id)
		{
			var deleteItem = _repNhaDat.SelectByID(id);
			var fileName = deleteItem.HinhMinhHoa;
			var idloaibatdongsan = deleteItem.IDLoaiBatDongSan;
			var idquanhuyen = deleteItem.IDQuanHuyen;
			var idloaigia = deleteItem.IDLoaiGia;
			var idnguoidang = deleteItem.IDNguoiDang;
			var result = _repNhaDat.Delete(id);
			if (result)
			{
                if (fileName != "nonhadat.jpg")
                {
                    var fullPath = Server.MapPath("/Content/Images/Items/" + fileName);
                    DeleteFile(fullPath);
                }
			}
			return Json(new{
				Success = result,
				RecordCount = _repNhaDat.SelectAll().Count,
				DeleteId = id
			});
		}

		public ActionResult DetailOfNhaDatDuAn(int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_NHADAT,
				EditID = id,
                IDNhaDat = id
			};
            return View("DetailOfNhaDatDuAn", CreateViewModel(data));
		}

        public ActionResult DetailOfNhaDatLe(int id)
        {
            var data = new DataTransferViewModel
            {
                EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_NHADAT,
                EditID = id,
                IDNhaDat = id
            };
            string tenloaibds = _repNhaDat.SelectByID(id).LoaiBatDongSan.TenLoaiBatDongSan.ToUpper();
            if (tenloaibds.Contains(WebConfiguration.CanHo))
                return View("DetailOfCanHoLe", CreateViewModel(data));
            return View("DetailOfNhaDatLe", CreateViewModel(data));
        }

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult UpdateNhaDatDuAn(FormCollection forms)
        {
            string id = forms.GetValues("NhaDat_ID")[0];
            string idloaibatdongsan = forms.GetValues("NhaDat_IDLoaiBatDongSan")[0];
            string idquanhuyen = forms.GetValues("NhaDat_IDQuanHuyen")[0];
            string idnguoidang = forms.GetValues("NhaDat_IDNguoiDang")[0];
            string diachi = forms.GetValues("NhaDat_DiaChi")[0];
            string tieude = forms.GetValues("NhaDat_TieuDe")[0];
            string noidung = forms.GetValues("NhaDat_NoiDung")[0];
            string noidungrutgon = forms.GetValues("NhaDat_NoiDungRutGon")[0];
            string tinvip = forms.GetValues("NhaDat_TinVip")[0];
            string tieubieu = forms.GetValues("NhaDat_TieuBieu")[0];
            string gia = forms.GetValues("NhaDat_Gia")[0];
            string idloaigia = forms.GetValues("NhaDat_IDLoaiGia")[0];
            var file = Request.Files["NhaDat_HinhMinhHoa"];
            string refName = "";
            var editItem = _repNhaDat.SelectByID(int.Parse(id));
            editItem.IDLoaiBatDongSan = int.Parse(idloaibatdongsan);
            editItem.IDQuanHuyen = int.Parse(idquanhuyen);
            editItem.IDNguoiDang = Guid.Parse(idnguoidang);
            editItem.DiaChi = diachi;
            editItem.TieuDe = tieude;
            editItem.NoiDung = noidung;
            editItem.NoiDungRutGon = noidungrutgon;
            editItem.TinVip = bool.Parse(tinvip);
            editItem.TieuBieu = bool.Parse(tieubieu);
            editItem.Gia = long.Parse(gia);
            editItem.IDLoaiGia = int.Parse(idloaigia);
            var result = false;
            if (file.ContentLength != 0)
            {
                result = UploadFile(file, "/Content/Images/Items/", id, ref refName);
                editItem.HinhMinhHoa = refName;
            }
            result = _repNhaDat.Save();
            var data = new DataTransferViewModel
            {
                IDLoaiBatDongSan = int.Parse(idloaibatdongsan),
                IDQuanHuyen = int.Parse(idquanhuyen),
                EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_NHADAT,
                EditID = int.Parse(id),
                Updated = result,
            };
            return View("DetailOfNhaDatDuAn", CreateViewModel(data));
        }

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateNhaDatLe(FormCollection forms)
		{
			string id = forms.GetValues("NhaDat_ID")[0];
			string idloaibatdongsan = forms.GetValues("NhaDat_IDLoaiBatDongSan")[0];
			string idquanhuyen = forms.GetValues("NhaDat_IDQuanHuyen")[0];
			string idloaigia = forms.GetValues("NhaDat_IDLoaiGia")[0];
			string idnguoidang = forms.GetValues("NhaDat_IDNguoiDang")[0];
			string gia = forms.GetValues("NhaDat_Gia")[0];
			string diachi = forms.GetValues("NhaDat_DiaChi")[0];
			string dientichngang = forms.GetValues("NhaDat_DienTichNgang")[0];
			string dientichdoc = forms.GetValues("NhaDat_DienTichDoc")[0];
			string dientichxaydung = forms.GetValues("NhaDat_DienTichXayDung")[0];
			string dientichsudung = forms.GetValues("NhaDat_DienTichSuDung")[0];
			string cosohong = forms.GetValues("NhaDat_CoSoHong")[0];
			string tieude = forms.GetValues("NhaDat_TieuDe")[0];
			string noidung = forms.GetValues("NhaDat_NoiDung")[0];
			string noidungrutgon = forms.GetValues("NhaDat_NoiDungRutGon")[0];
			string tinvip = forms.GetValues("NhaDat_TinVip")[0];
            string tieubieu = forms.GetValues("NhaDat_TieuBieu")[0];
			var file = Request.Files["NhaDat_HinhMinhHoa"];
			string refName = "";
			var editItem = _repNhaDat.SelectByID(int.Parse(id));
			editItem.IDLoaiBatDongSan = int.Parse(idloaibatdongsan);
			editItem.IDQuanHuyen = int.Parse(idquanhuyen);
			editItem.IDLoaiGia = int.Parse(idloaigia);
			editItem.IDNguoiDang = Guid.Parse(idnguoidang);
			editItem.Gia = long.Parse(gia);
			editItem.DiaChi = diachi;
			editItem.DienTichNgang = int.Parse(dientichngang);
			editItem.DienTichDoc = int.Parse(dientichdoc);
			editItem.DienTichXayDung = double.Parse(dientichxaydung);
			editItem.DienTichSuDung = double.Parse(dientichsudung);
			editItem.CoSoHong = bool.Parse(cosohong);
			editItem.TieuDe = tieude;
			editItem.NoiDung = noidung;
			editItem.NoiDungRutGon = noidungrutgon;
			editItem.TinVip = bool.Parse(tinvip);
            editItem.TieuBieu = bool.Parse(tieubieu);
            var result = false;
            if (file.ContentLength != 0)
            {
                result = UploadFile(file, "/Content/Images/Items/", id, ref refName);
                editItem.HinhMinhHoa = refName;
            }
            result = _repNhaDat.Save();
            if (result)
            {
                //update van hoa xa hoi
                UpdateVanHoaXaHoi(forms, editItem.ID);
                if (editItem.LoaiBatDongSan.TenLoaiBatDongSan.ToUpper().Contains(WebConfiguration.CanHo))
                {
                    //update tien ich
                    UpdateTienIch(forms, editItem.ID);
                    //update tien ich khac
                    UpdateTienIchKhac(forms, editItem.ID);
                    UpdateThongTinCanHoLe(forms, editItem.ID);
                }
            }
			var data = new DataTransferViewModel
			{
                IDLoaiBatDongSan = int.Parse(idloaibatdongsan),
                IDQuanHuyen = int.Parse(idquanhuyen),
				EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_NHADAT,
				EditID = int.Parse(id),
				Updated = result,
			};
            string tenloaibds = editItem.LoaiBatDongSan.TenLoaiBatDongSan.ToUpper();
            if (tenloaibds.Contains(WebConfiguration.CanHo))
                return View("DetailOfCanHoLe", CreateViewModel(data));
            return View("DetailOfNhaDatLe", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertNhaDatDuAn(FormCollection forms)
		{
			string idloaibatdongsan = forms.GetValues("NhaDat_IDLoaiBatDongSan")[0];
			string idquanhuyen = forms.GetValues("NhaDat_IDQuanHuyen")[0];
			string idnguoidang = forms.GetValues("NhaDat_IDNguoiDang")[0];
			string diachi = forms.GetValues("NhaDat_DiaChi")[0];
			string tieude = forms.GetValues("NhaDat_TieuDe")[0];
			string noidung = forms.GetValues("NhaDat_NoiDung")[0];
			string noidungrutgon = forms.GetValues("NhaDat_NoiDungRutGon")[0];
			string ngaydang = forms.GetValues("NhaDat_NgayDang")[0];
			string tinvip = forms.GetValues("NhaDat_TinVip")[0];
            string tieubieu = forms.GetValues("NhaDat_TieuBieu")[0];
            string gia = forms.GetValues("NhaDat_Gia")[0];
            string idloaigia = forms.GetValues("NhaDat_IDLoaiGia")[0];
			var file = Request.Files["NhaDat_HinhMinhHoa"];
			string refName = "";
			var newItem = new NhaDat
			{
				IDLoaiBatDongSan = int.Parse(idloaibatdongsan),
				IDQuanHuyen = int.Parse(idquanhuyen),
				IDNguoiDang = Guid.Parse(idnguoidang),
				DiaChi = diachi,
                TieuDe = tieude,
				NoiDung = noidung,
				NoiDungRutGon = noidungrutgon,
				NgayDang = DateTime.Parse(ngaydang),
				TinVip = bool.Parse(tinvip),
                TieuBieu = bool.Parse(tieubieu),
                HinhMinhHoa = "nonhadat.jpg",
                Gia = gia == "" ? 0 : long.Parse(gia),
                IDLoaiGia = int.Parse(idloaigia),
                SoLanXem = 0
			};
			var result = _repNhaDat.Insert(newItem);
			if (result)
			{
                if (file.ContentLength != 0)
                {
                    result = UploadFile(file, "/Content/Images/Items/", newItem.ID.ToString(), ref refName);
                    if (result)
                    {
                        var addedItem = _repNhaDat.SelectByID(newItem.ID);
                        addedItem.HinhMinhHoa = refName;
                        _repNhaDat.Save();
                    }
                }
			}
			var data = new DataTransferViewModel
			{
                IDLoaiBatDongSan = int.Parse(idloaibatdongsan),
                IDQuanHuyen = int.Parse(idquanhuyen),
				EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
				Added = result,
			};
            return View("SelectNhaDatDuAn", CreateViewModel(data));
		}

        [ValidateInput(false)]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult InsertNhaDatLe(FormCollection forms)
        {
            string idloaibatdongsan = forms.GetValues("NhaDat_IDLoaiBatDongSan")[0];
            string idquanhuyen = forms.GetValues("NhaDat_IDQuanHuyen")[0];
            string idloaigia = forms.GetValues("NhaDat_IDLoaiGia")[0];
            string idnguoidang = forms.GetValues("NhaDat_IDNguoiDang")[0];
            string gia = forms.GetValues("NhaDat_Gia")[0];
            string diachi = forms.GetValues("NhaDat_DiaChi")[0];
            string dientichngang = forms.GetValues("NhaDat_DienTichNgang")[0];
            string dientichdoc = forms.GetValues("NhaDat_DienTichDoc")[0];
            string dientichxaydung = forms.GetValues("NhaDat_DienTichXayDung")[0];
            string dientichsudung = forms.GetValues("NhaDat_DienTichSuDung")[0];
            string cosohong = forms.GetValues("NhaDat_CoSoHong")[0];
            string tieude = forms.GetValues("NhaDat_TieuDe")[0];
            string noidung = forms.GetValues("NhaDat_NoiDung")[0];
            string noidungrutgon = forms.GetValues("NhaDat_NoiDungRutGon")[0];
            string ngaydang = forms.GetValues("NhaDat_NgayDang")[0];
            string tinvip = forms.GetValues("NhaDat_TinVip")[0];
            string tieubieu = forms.GetValues("NhaDat_TieuBieu")[0];
            var file = Request.Files["NhaDat_HinhMinhHoa"];
            string refName = "";
            var newItem = new NhaDat
            {
                IDLoaiBatDongSan = int.Parse(idloaibatdongsan),
                IDQuanHuyen = int.Parse(idquanhuyen),
                IDLoaiGia = int.Parse(idloaigia),
                IDNguoiDang = Guid.Parse(idnguoidang),
                Gia = gia == "" ? 0 : long.Parse(gia),
                DiaChi = diachi,
                DienTichNgang = dientichngang == "" ? 0 : int.Parse(dientichngang),
                DienTichDoc = dientichdoc == "" ? 0 : int.Parse(dientichdoc),
                DienTichXayDung = dientichxaydung == "" ? 0 : double.Parse(dientichxaydung),
                DienTichSuDung = dientichsudung == "" ? 0 : double.Parse(dientichsudung),
                CoSoHong = bool.Parse(cosohong),
                TieuDe = tieude,
                NoiDung = noidung,
                NoiDungRutGon = noidungrutgon,
                NgayDang = DateTime.Parse(ngaydang),
                TinVip = bool.Parse(tinvip),
                TieuBieu = bool.Parse(tieubieu),
                HinhMinhHoa = "nonhadat.jpg",
                SoLanXem = 0
            };
            var result = _repNhaDat.Insert(newItem);
            if (result)
            {
                if (file.ContentLength != 0)
                {
                    result = UploadFile(file, "/Content/Images/Items/", newItem.ID.ToString(), ref refName);
                    if (result)
                    {
                        var addedItem = _repNhaDat.SelectByID(newItem.ID);
                        addedItem.HinhMinhHoa = refName;
                        _repNhaDat.Save();
                    }
                }
            }
            if (result)
            {
                //add van hoa xa hoi
                InsertVanHoaXaHoi(forms, newItem.ID);
                if (newItem.LoaiBatDongSan.TenLoaiBatDongSan.ToUpper().Contains(WebConfiguration.CanHo))
                {
                    //add tien ich
                    InsertTienIch(forms, newItem.ID);
                    //add tien ich khac
                    InsertTienIchKhac(forms, newItem.ID);
                    //add thong tin can ho le
                    InsertThongTinCanHoLe(forms, newItem.ID);
                }
            }
            var data = new DataTransferViewModel
            {
                IDLoaiBatDongSan = int.Parse(idloaibatdongsan),
                IDQuanHuyen = int.Parse(idquanhuyen),
                EnumViewModelType = EnumViewModel.ADMIN_NHADAT,
                Added = result,
            };
            string tenloaibds = newItem.LoaiBatDongSan.TenLoaiBatDongSan.ToUpper();
            if (tenloaibds.Contains(WebConfiguration.CanHo))
                return View("SelectCanHoLe", CreateViewModel(data));
            return View("SelectNhaDatLe", CreateViewModel(data));
        }

        public void InsertThongTinCanHoLe(FormCollection forms, int idnhadat)
        {
            string sotang = forms.GetValues("NhaDat_SoTang")[0];
            string sophongngu = forms.GetValues("NhaDat_SoPhongNgu")[0];
            string namxaydung = forms.GetValues("NhaDat_NamXayDung")[0];
            string sophongtam = forms.GetValues("NhaDat_SoPhongTam")[0];
            string huong = forms.GetValues("NhaDat_Huong")[0];
            string loainoithat = forms.GetValues("NhaDat_LoaiNoiThat")[0];
            string namsuachua = forms.GetValues("NhaDat_NamSuaChua")[0];
            string nohau = forms.GetValues("NhaDat_NoHau")[0];
            string mattien = forms.GetValues("NhaDat_MatTien")[0];
            var newItem = new ThongTinCanHoLe
            {
                IDNhaDat = idnhadat,
                SoTang = sotang,
                SoPhongNgu = sophongngu,
                NamXayDung = namxaydung,
                SoPhongTam = sophongtam,
                Huong = huong,
                LoaiNoiThat = loainoithat,
                NamSuaChua = namsuachua,
                NoHau = bool.Parse(nohau),
                MatTien = bool.Parse(mattien)
            };
            var result = _repThongTinCanHoLe.Insert(newItem);
        }

        public void InsertTienIch(FormCollection forms, int idnhadat)
        {
            string donghodien = forms.GetValues("TienIch_DongHoDien")[0];
            string donghonuoc = forms.GetValues("TienIch_DongHoNuoc")[0];
            string mayphatdien = forms.GetValues("TienIch_MayPhatDien")[0];
            string maybomnuoc = forms.GetValues("TienIch_MayBomNuoc")[0];
            string giengdong = forms.GetValues("TienIch_GiengDong")[0];
            var newItem = new TienIch
            {
                IDNhaDat = idnhadat,
                DongHoDien = bool.Parse(donghodien),
                DongHoNuoc = bool.Parse(donghonuoc),
                MayPhatDien = bool.Parse(mayphatdien),
                MayBomNuoc = bool.Parse(maybomnuoc),
                GiengDong = bool.Parse(giengdong)
            };
            var result = _repTienIch.Insert(newItem);
        }

        public void InsertTienIchKhac(FormCollection forms, int idnhadat)
        {
            string garaoto = forms.GetValues("TienIchKhac_GaraOto")[0];
            string maylanh = forms.GetValues("TienIchKhac_MayLanh")[0];
            string truyenhinhcap = forms.GetValues("TienIchKhac_TruyenHinhCap")[0];
            string sanvuon = forms.GetValues("TienIchKhac_SanVuon")[0];
            string maynuocnong = forms.GetValues("TienIchKhac_MayNuocNong")[0];
            string internet = forms.GetValues("TienIchKhac_Internet")[0];
            string dienthoai = forms.GetValues("TienIchKhac_DienThoai")[0];
            string chodauxehoi = forms.GetValues("TienIchKhac_ChoDauXeHoi")[0];
            string hoboi = forms.GetValues("TienIchKhac_HoBoi")[0];
            var newItem = new TienIchKhac
            {
                IDNhaDat = idnhadat, 
                GaraOto = bool.Parse(garaoto),
                MayLanh = bool.Parse(maylanh),
                TruyenHinhCap = bool.Parse(truyenhinhcap),
                SanVuon = bool.Parse(sanvuon),
                MayNuocNong = bool.Parse(maynuocnong),
                Internet = bool.Parse(internet),
                DienThoai = bool.Parse(dienthoai),
                ChoDauXeHoi = bool.Parse(chodauxehoi),
                HoBoi = bool.Parse(hoboi)
            };
            var result = _repTienIchKhac.Insert(newItem);
        }

        public void InsertVanHoaXaHoi(FormCollection forms, int idnhadat)
        {
            string gantruongmaugiao = forms.GetValues("VanHoaXaHoi_GanTruongMauGiao")[0];
            string gantruongcap1 = forms.GetValues("VanHoaXaHoi_GanTruongCap1")[0];
            string gantruongcap2 = forms.GetValues("VanHoaXaHoi_GanTruongCap2")[0];
            string gantruongcap3 = forms.GetValues("VanHoaXaHoi_GanTruongCap3")[0];
            string gantruongdhcd = forms.GetValues("VanHoaXaHoi_GanTruongDHCD")[0];
            string gantrungtamthuongmai = forms.GetValues("VanHoaXaHoi_GanTrungTamThuongMai")[0];
            string khudantricao = forms.GetValues("VanHoaXaHoi_KhuDanTriCao")[0];
            string gancho = forms.GetValues("VanHoaXaHoi_GanCho")[0];
            string gancongvien = forms.GetValues("VanHoaXaHoi_GanCongVien")[0];
            string ganbenhvien = forms.GetValues("VanHoaXaHoi_GanBenhVien")[0];
            string gantrungtamgiaitri = forms.GetValues("VanHoaXaHoi_GanTrungTamGiaiTri")[0];
            string tienkinhdoanh = forms.GetValues("VanHoaXaHoi_TienKinhDoanh")[0];
            var newItem = new VanHoaXaHoi
            {
                IDNhaDat = idnhadat, 
                GanTruongMauGiao = bool.Parse(gantruongmaugiao),
                GanTruongCap1 = bool.Parse(gantruongcap1),
                GanTruongCap2 = bool.Parse(gantruongcap2),
                GanTruongCap3 = bool.Parse(gantruongcap3),
                GanTruongDHCD = bool.Parse(gantruongdhcd),
                GanTrungTamThuongMai = bool.Parse(gantrungtamthuongmai),
                KhuDanTriCao = bool.Parse(khudantricao),
                GanCho = bool.Parse(gancho),
                GanCongVien = bool.Parse(gancongvien),
                GanBenhVien = bool.Parse(ganbenhvien),
                GanTrungTamGiaiTri = bool.Parse(gantrungtamgiaitri),
                TienKinhDoanh = bool.Parse(tienkinhdoanh)
            };
            var result = _repVanHoaXaHoi.Insert(newItem);
        }

        public void UpdateThongTinCanHoLe(FormCollection forms, int idnhadat)
        {
            string sotang = forms.GetValues("NhaDat_SoTang")[0];
            string sophongngu = forms.GetValues("NhaDat_SoPhongNgu")[0];
            string namxaydung = forms.GetValues("NhaDat_NamXayDung")[0];
            string sophongtam = forms.GetValues("NhaDat_SoPhongTam")[0];
            string huong = forms.GetValues("NhaDat_Huong")[0];
            string loainoithat = forms.GetValues("NhaDat_LoaiNoiThat")[0];
            string namsuachua = forms.GetValues("NhaDat_NamSuaChua")[0];
            string nohau = forms.GetValues("NhaDat_NoHau")[0];
            string mattien = forms.GetValues("NhaDat_MatTien")[0];

            var thongtin = _repThongTinCanHoLe.SelectByID(idnhadat);

            thongtin.SoTang = sotang;
            thongtin.SoPhongNgu = sophongngu;
            thongtin.NamXayDung = namxaydung;
            thongtin.SoPhongTam = sophongtam;
            thongtin.Huong = huong;
            thongtin.LoaiNoiThat = loainoithat;
            thongtin.NamSuaChua = namsuachua;
            thongtin.NoHau = bool.Parse(nohau);
            thongtin.MatTien = bool.Parse(mattien);

            var result = _repThongTinCanHoLe.Save();
        }

        public void UpdateTienIch(FormCollection forms, int idnhadat)
        {
            string donghodien = forms.GetValues("TienIch_DongHoDien")[0];
            string donghonuoc = forms.GetValues("TienIch_DongHoNuoc")[0];
            string mayphatdien = forms.GetValues("TienIch_MayPhatDien")[0];
            string maybomnuoc = forms.GetValues("TienIch_MayBomNuoc")[0];
            string giengdong = forms.GetValues("TienIch_GiengDong")[0];
            var tienich = _repTienIch.SelectByID(idnhadat);
            tienich.DongHoDien = bool.Parse(donghodien);
            tienich.DongHoNuoc = bool.Parse(donghonuoc);
            tienich.MayPhatDien = bool.Parse(mayphatdien);
            tienich.MayBomNuoc = bool.Parse(maybomnuoc);
            tienich.GiengDong = bool.Parse(giengdong);
            var result = _repTienIch.Save();
        }

        public void UpdateTienIchKhac(FormCollection forms, int idnhadat)
        {
            string garaoto = forms.GetValues("TienIchKhac_GaraOto")[0];
            string maylanh = forms.GetValues("TienIchKhac_MayLanh")[0];
            string truyenhinhcap = forms.GetValues("TienIchKhac_TruyenHinhCap")[0];
            string sanvuon = forms.GetValues("TienIchKhac_SanVuon")[0];
            string maynuocnong = forms.GetValues("TienIchKhac_MayNuocNong")[0];
            string internet = forms.GetValues("TienIchKhac_Internet")[0];
            string dienthoai = forms.GetValues("TienIchKhac_DienThoai")[0];
            string chodauxehoi = forms.GetValues("TienIchKhac_ChoDauXeHoi")[0];
            string hoboi = forms.GetValues("TienIchKhac_HoBoi")[0];
            var tienichkhac = _repTienIchKhac.SelectByID(idnhadat);
            tienichkhac.GaraOto = bool.Parse(garaoto);
            tienichkhac.MayLanh = bool.Parse(maylanh);
            tienichkhac.TruyenHinhCap = bool.Parse(truyenhinhcap);
            tienichkhac.SanVuon = bool.Parse(sanvuon);
            tienichkhac.MayNuocNong = bool.Parse(maynuocnong);
            tienichkhac.Internet = bool.Parse(internet);
            tienichkhac.DienThoai = bool.Parse(dienthoai);
            tienichkhac.ChoDauXeHoi = bool.Parse(chodauxehoi);
            tienichkhac.HoBoi = bool.Parse(hoboi);
            var result = _repTienIchKhac.Save();
        }

        public void UpdateVanHoaXaHoi(FormCollection forms, int idnhadat)
        {
            string gantruongmaugiao = forms.GetValues("VanHoaXaHoi_GanTruongMauGiao")[0];
            string gantruongcap1 = forms.GetValues("VanHoaXaHoi_GanTruongCap1")[0];
            string gantruongcap2 = forms.GetValues("VanHoaXaHoi_GanTruongCap2")[0];
            string gantruongcap3 = forms.GetValues("VanHoaXaHoi_GanTruongCap3")[0];
            string gantruongdhcd = forms.GetValues("VanHoaXaHoi_GanTruongDHCD")[0];
            string gantrungtamthuongmai = forms.GetValues("VanHoaXaHoi_GanTrungTamThuongMai")[0];
            string khudantricao = forms.GetValues("VanHoaXaHoi_KhuDanTriCao")[0];
            string gancho = forms.GetValues("VanHoaXaHoi_GanCho")[0];
            string gancongvien = forms.GetValues("VanHoaXaHoi_GanCongVien")[0];
            string ganbenhvien = forms.GetValues("VanHoaXaHoi_GanBenhVien")[0];
            string gantrungtamgiaitri = forms.GetValues("VanHoaXaHoi_GanTrungTamGiaiTri")[0];
            string tienkinhdoanh = forms.GetValues("VanHoaXaHoi_TienKinhDoanh")[0];
            var vanhoaxahoi = _repVanHoaXaHoi.SelectByID(idnhadat);
            vanhoaxahoi.GanTruongMauGiao = bool.Parse(gantruongmaugiao);
            vanhoaxahoi.GanTruongCap1 = bool.Parse(gantruongcap1);
            vanhoaxahoi.GanTruongCap2 = bool.Parse(gantruongcap2);
            vanhoaxahoi.GanTruongCap3 = bool.Parse(gantruongcap3);
            vanhoaxahoi.GanTruongDHCD = bool.Parse(gantruongdhcd);
            vanhoaxahoi.GanTrungTamThuongMai = bool.Parse(gantrungtamthuongmai);
            vanhoaxahoi.KhuDanTriCao = bool.Parse(khudantricao);
            vanhoaxahoi.GanCho = bool.Parse(gancho);
            vanhoaxahoi.GanCongVien = bool.Parse(gancongvien);
            vanhoaxahoi.GanBenhVien = bool.Parse(ganbenhvien);
            vanhoaxahoi.GanTrungTamGiaiTri = bool.Parse(gantrungtamgiaitri);
            vanhoaxahoi.TienKinhDoanh = bool.Parse(tienkinhdoanh);
            var result = _repVanHoaXaHoi.Save();
        }
	}
}